<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>添加和修改员工</title>
	<%@ include file="/view/common/tags.jsp"%>
</head>
<body>
	<div class="well well_p" >
		<sk:form method="post" cssClass="form-horizontal" action=""  id="saveAndUpdateFrom" target="_parent"  >
			<div class="form-group">
				<label class="col-xs-3 text-right">映射路径:</label>
				<div class="col-xs-7">
					<input type="text" class="form-control" name="path" id="path" value="<%=request.getParameter("path")%>" placeholder="映射路径">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-3 text-right">服务ID:</label>
				<div class="col-xs-7">
					<input type="text" class="form-control" name="serviceId" id="serviceId" value="<%=request.getParameter("serviceId")%>" placeholder="服务ID">
				</div>
			</div>
			<div class="form-group" >
				<label class="col-xs-3 text-right">是否去掉前缀:</label>
				<div class="col-xs-7">
                    <td colspan="2">
                        <label for="port"><input id="yse" name="stripPrefix" type="radio" <%="0".equals(request.getParameter("stripPrefix")) ? "checked" : ""%> ${stripPrefix == '0' ? 'checked' : ''} value="0"/>&nbsp;是</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <label for="no"><input id="no" name="stripPrefix" type="radio" <%="1".equals(request.getParameter("stripPrefix")) ? "checked" : ""%> value="1"/>&nbsp;否</label>
                    </td>
				</div>
			</div>
			<div class="form-group" >
				<label class="col-xs-3 text-right">是否重试:</label>
				<div class="col-xs-7">
                    <label for="port"><input id="yse1" name="retryable" type="radio" <%="0".equals(request.getParameter("retryable")) ? "checked" : ""%> value="0"/>&nbsp;是</label>&nbsp;&nbsp;&nbsp;&nbsp;
                    <label for="no"><input id="no1" name="retryable" type="radio" <%="1".equals(request.getParameter("retryable")) ? "checked" : ""%> value="1"/>&nbsp;否</label>
				</div>
			</div>
			<input type="hidden" id="rowId" name="rowId" value="<%=request.getParameter("rowId")%>">
			<input type="hidden" id="isReCommit" value="0">
		</sk:form>
	</div>
</body>
   <%@ include file="/view/common/footer.jsp"%>
   <script type="text/javascript">
   $(function(){
       var rowId = $('#rowId').val();
	   if(rowId == 0){
		   $("#path").val("");
		   $("#serviceId").val("");
	   }
   });
   
   var err = {'1':'添加','2':'修改'};
   var action = {'1':'${routerAdd}','2':'${routerUpdate}'};
   function add(){
       var rowId = $('#rowId').val();
       var i;
       if (!CheckUtil.isNotNull(rowId) || rowId == 0) {
           i = 1;//添加
       } else {
           i = 2;//修改
       }
       var path = $.trim($("#path").val());
       $("#path").val(path);
       if (!CheckUtil.isNotNull(path)) {
           layer.msg("请输入映射路径!");
           return;
       }
       
       var serviceId = $.trim($("#serviceId").val());
       $("#serviceId").val(serviceId);//渠道游戏ID去空格
       if (!CheckUtil.isNotNull(serviceId)) {
           layer.msg("请输入服务ID!");
           return;
       }
       
       if ($("#isReCommit").val() == 0) {
           $("#isReCommit").val(1);
           
           //loading层
           var index = layer.load(0, {
               shade: [0.1,'#fff'] //0.1透明度的白色背景
           });
           $.ajax({
               url: action[i],
               type: "post",
               cache: false,
               data: new FormData($("#saveAndUpdateFrom")[0]),
               dataType:"json",
               processData: false,
               contentType: false,
               async:false,
               success: function(data) {
            	   layer.close(index);
                   if(data.code == 0){
                	   if(i == 1){
                           parent.layer.msg("添加路由成功！");
                	   }else{
                		   parent.layer.msg("修改路由成功！");
                	   }
                       parent.findData();
                       parent.layer.close(parent.tableIndex);
                   } else {
                       parent.layer.msg(data.message);
                   }
               }
           });
       }
   }
   
   </script>
</html>